package com.example;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: dlernatovich
 * Date: 6/27/12
 * Time: 12:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class OptimyzeArrayAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final List<String> values;

    static class ViewHolder {
        public TextView text;
        public ImageView image;
    }

    public OptimyzeArrayAdapter(Activity context, int textViewResourceId, List<String> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        this.values = objects;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        if (rowView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.custom_list_data, null);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.text = (TextView) rowView.findViewById(R.id.listText);
            viewHolder.image = (ImageView) rowView
                    .findViewById(R.id.listIcon);
            rowView.setTag(viewHolder);
        }

        ViewHolder holder = (ViewHolder) rowView.getTag();
        String s = values.get(position);
        holder.text.setText(s);
        if (s.startsWith("Option 4") || s.startsWith("Option 3")
                || s.startsWith("Option 5")||s.startsWith("Option 6")) {
            holder.image.setImageResource(android.R.drawable.ic_menu_add);
        } else {
            holder.image.setImageResource(android.R.drawable.ic_menu_call);
        }

        return rowView;
    }

}
